<!doctype html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<title>北京循一堂健康管理有限公司</title>
	<link rel="stylesheet" href="../css/page.css">
	<link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css">
	<link href="../plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" type="text/css">
	<script src="../js/jquery.min.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../plugins/select/js/bootstrap-select.min.js"></script>

	<script src="../plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="../plugins/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
</head>

<body>
	<div class="white_content"></div>

	<!--开方-->
	<div class="container-2" id="kf">
		<!-- 选择药方后弹出遮罩层 -->
		<div id="xyt_kf_yfmb_popLayer"></div>
		<!-- 选择药方后弹出遮罩层结束 -->
		<a href="javascript:void(0)" onclick="parent.ymPrompt.doHandler('close');">
			<button type="button" class="go-back">&lt;返回视频</button></a>
		<div class="tip">
			<p>
				<span><b>就诊编号：</b><span id="kf-patientno">IK009821</span></span>
				<span><b>姓名：</b><span id="kf-patientname">张三</span></span>
				<span><b>性别：</b><span id="kf-patientsex">男</span></span>
				<span><b>年龄：</b><span id="kf-patientage">56</span></span>
				<span><b>病史：</b><span id="kf-patienthistory"></span></span>
			</p>
			<p><b>诊断：</b>——————————————————————————————————————————————————</p>
			<p><b>处理意见：</b>——————————————————————————————————————————————————</p>
		</div>

		<div class="notice">
			<div class="tab-hd">
				<ul class="tab-nav">
					<!-- <li>草药</li> -->
					<li>颗粒剂</li>
				</ul>

			</div>
			<div class="tab-bd">
				<div class="tab-pal clearfix">
					<div class="xyt_kf_nav">
						<ul class="xyt_kf_zt">
							<li>嘱托：</li>
							<li>共<input></input>付，</li>
							<li>每日<input></input>次;</li>
							<li>使用：
								<select>
									<option>口服</option>
									<option>外用</option>
								</select>
							</li>
						</ul>
						<button class="xyt_kf_xzmb" id="xyt_kf_yfmb_popBox_btn">选择模板</button>
						<div id="xyt_kf_yfmb_popBox">
							<div class="xyt_kf_yfmb_close">
								<a href="javascript:void(0)" id="xyt_kf_yfmb_closeBox_btn"><li></li></a>
							</div>
							<div class="xyt_kf_yfmb_content">
								<button id="select-prescript-btn">选择药方</button>
								<div class="xyt_kf_yfmb_content_left">
									<ul>
										<li class="xyt_kf_yfmb_content_left_tatil">请选择药方模板</li>
									</ul>
									<ul class="xyt_kf_yfmb_content_left_ul1" id="xyt_kf_yfmb_content_left_ul1_list">
										
									</ul>
								</div>
								<div class="xyt_kf_yfmb_content_right">
									<ul>
										<li class="xyt_kf_yfmb_content_right_tatil">请选择药品</li>
									</ul>
									<ul class="xyt_kf_yfmb_content_right_ul1">
											<table id="userTable"></table>
									</ul>
									
								</div>
							</div>
						</div>
					</div>
					<button type="submit" class="sure save-btn">保存药方</button>
					<ul style=" float:left; width: 557px;">
						<li class="lf-tab" id="perscript-table-keli">处方药</li>
						<ul style="border-left: solid 1px #d9d9d9; overflow: hidden; float: left;" id="perscript-list-ul">
							<li class="lf-tab2">
								<span style="width: 100px;">名称</span><span
									style="width: 10px; float: right;">g</span><span
									style="width: 65px; float: right; text-align: right;">15</span>
							</li>
						</ul>
					</ul>
					<ul style=" float:right; width: 734px;">
						<!-- <form class="form-inline" role="form">
								<div class="form-group" style="position: absolute; top: -3px; right: 230px;">
								  <input type="text" class="form-control" id="spell-name-keli" placeholder="请输入药品简拼搜索">
								</div>
							  </form> -->
						<table border="" cellspacing="" cellpadding="" width="734" class="rg-tab"
							id="caoyao-table-keli">
							<tr>
								<th width="30px">序号</th>
								<th width="130px" class="t-i10">药品名称</th>
								<th width="50px" class="t-i10">用量</th>
								<th width="30px">单位</th>
								<th width="180px">备注</th>
								<th width="62px">单价</th>
								<th width="60px">金额</th>
								<th width="80px">操作</th>
							</tr>
							<tr>
								<td></td>
								<td><input class="search-name-input" id="email"></input>
									<ul class="xyt_medical_list"></ul>
								</td>
								<td><input style="width: 50px;"></input></td>
								<td></td>
								<td><input></input></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>

						</table>
					</ul>
				</div>

			</div>
		</div>

	</div>

	</div>
	<script src="../js/main-up.js"></script>
	<script>
		window.baseUrl = localStorage.getItem("baseUrl");
		window.sessionid = localStorage.getItem("sessionid");
		window.selectpescriptid="";
		var doctorId=localStorage.getItem("doctorId"); 
		$(function () {

			var $table = $('#userTable');
			var $remove = $('#btn_delete'),
				$add = $('#btn_add'),
				$edit = $('#btn_edit'),
				toolbar = "#userToolbar";

			$table.bootstrapTable({
				contentType: "application/x-www-form-urlencoded",
				method: "post",
				toolbar: toolbar,
				//showRefresh: true,
				//showToggle: true,
				pagination: false,
				//showColumns: true,
				idField: "id",
				sortName: 'createtime',
				sortOrder: 'desc',
				pageSize: 10,
				pageList: [10, 25, 50, 100],
				queryParamsType: "",
				queryParams: function (params) {
					//将查询条件添加到查询参数中，分页或者刷新时将携带这些参数
					params["pageNumber"] = params.pageNumber;
					params["pageSize"] = params.pageSize;
					params["sortOrder"] = params.sortOrder;
					params["sortName"] = params.sortName;
					params["perscriptid"] = window.selectpescriptid;
					return params;
				},
				sidePagination: "server",
				url: window.baseUrl + "/xunyitang/westPrescriptMedical/permedlist?jsessionid=" + window.sessionid,
				columns: [{
						field: "state",
						checkbox: true
					},
					{
						field: "id",
						title: "编号"
					},
					{
						field: "medname",
						title: "药品名称",
						//sortable: true
					},
					{
						field: "medcount",
						title: "用量",
					//	sortable: true
					},
					{
						field: "meddosage",
						title: "单位",
					//	sortable: true
					},
					{
						field: "medprice",
						title: "单价",
					//	sortable: true
					},
					{
						field: "medtotal",
						title: "金额",
					//	sortable: true
					}
				],
				onLoadError: function () { //加载失败时执行
					window.location.href = "../index.html";
				}
			});
			$table.on('check.bs.table uncheck.bs.table ' +
				'check-all.bs.table uncheck-all.bs.table',
				function () {
					initBtnStatus();
				});
			//数据已添加到table中，onPostBody
			$table.on('post-body.bs.table', function (data) {
				initBtnStatus();
				//为按钮绑定事件
			});

			//数据加载完成事件，onLoadSuccess
			$table.on('load-success.bs.table', function () {
				initBtnStatus();
			});

			function initBtnStatus() {
				var len = $table.bootstrapTable('getSelections').length;
				$add.prop('disabled', !len);
				// $edit.prop('disabled', len!=1);
			}

			function getIdSelections() {
				return $.map($table.bootstrapTable('getSelections'), function (row) {
					return row.medid
				});
			}

			$("#select-prescript-btn").click(function(){
				var lists=getIdSelections();
				if(null!=lists && lists.length>0){
					
					$("#xyt_kf_yfmb_popBox").hide();
					$("#xyt_kf_yfmb_popLayer").hide();
				}else{
					alert("请选择药方");
				}

			});
            //刷新并跳转到第一页页面
            function refresh() {
                //刷新并跳转到第一页
                //$table.bootstrapTable('selectPage', 1);
                $table.bootstrapTable('refresh');
            };

						$(".add-2").click(function () {
							alert("enter");
							return;
								var id = $(this).data().id;
								var name = $(this).data().name;
								var dosage = $(this).data().dosage;
								var price = $(this).data().price;
								$("#perscript-list-ul").append('<tr><td><th>' + name +
									'</th><th>' + medical.spell + '</th></td></tr>');
								med1Array.push(id);
								$(".xyt_kf_scyp").click(function () {

									var tempid = $(this).data().id;
									var index = med1Array.indexOf(tempid);
									if (index > -1) {
										med1Array.splice(index, 1);
									}

									$(this).parent().parent().remove();
								});
							});

			$("#spell-name-keli").on(" input propertychange", function () {
				var keyword = $("#spell-name-keli").val();
				if (null == keyword || keyword.length == 0) return;
				$.ajax({
					type: "POST",
					url: window.baseUrl + "/xunyitang/westMedical/medicallist?jsessionid=" + window
						.sessionid,
					contentType: "application/x-www-form-urlencoded",
					data: {
						keyword: keyword,
						type: "keli"
					},
					dataType: "json",
					async: false,
					beforeSend: function (request) {
						request.setRequestHeader("Token", localStorage.getItem("Authorization"));
					},
					success: function (data) {
						if (null != data && null != data.rows) {
							$("#caoyao-table-keli").empty();
							$("#caoyao-table-keli").append(
								'<tr><th width="30px">序号</th><th width="130px" class="t-i10">药品名称</th><th width="50px" class="t-i10">用量</th><th width="30px">单位</th><th width="180px">备注</th><th width="62px">单价</th><th width="60px">金额</th><th width="80px">操作</th></tr>'
								);
							for (let i = 0; i < data.rows.length; i++) {
								var medical = data.rows[i];
								$("#caoyao-table-keli").append(
									'<tr><td></td><td><input></input></td><td><input style="width: 50px;"></input></td><td>' +
									medical.dosage + '</td><td><input></input></td><td>' +
									medical.level + '</td>' + '<td>' + medical.price +
									'</td><td><button data-id="' + medical.id +
									'" data-name="' + medical.name + '" data-dosage="' +
									medical.dosage + '" data-price="' + medical.price +
									'" type="button" class="add-2"></button><button data-id="' +
									medical.id + '" data-name="' + medical.name +
									'" data-dosage="' + medical.dosage + '" data-price="' +
									medical.price +
									'" type="button" class="add-3"></button></td></tr>');
							}
						}

					},
					error: function (data) {
						parent.ymPrompt.doHandler('close');
						window.location.href = "../index.html";
					}
				});
			})

			// $(".search-name-input").keypress(function (e) {
			// 	if (e.which == 13) {
			// 		$(this).parent().parent().before(
			// 			'<tr><td></td><td><input></input></td><td><input style="width: 50px;"></input></td><td></td><td><input></input></td><td></td><td></td><td><button type="button" class="add-2"></button><button  type="button" class="add-3"></button></td></tr>'
			// 			);
			// 	}
			// });
			$(".save-btn").click(function () {
				var numArr = []; // 定义一个空数组
				var txt = $('#perscript-table').find(':text'); // 获取所有文本框
				for (var i = 0; i < txt.length; i++) {
					numArr.push(txt.eq(i).val()); // 将文本框的值添加到数组中
				}
				console.info(numArr);

				var numArr1 = []; // 定义一个空数组
				var txt1 = $('#perscript-table-keli').find(':text'); // 获取所有文本框
				for (var i = 0; i < txt1.length; i++) {
					numArr1.push(txt1.eq(i).val()); // 将文本框的值添加到数组中
				}
				console.info(numArr1);

				var patientid = localStorage.getItem("sessionpatientid");
				var doctorid = localStorage.getItem("doctorId");
				$.ajax({
					type: "POST",
					url: window.baseUrl +
						"/xunyitang/westPrescriptMedical/savepermedlist?jsessionid=" + window
						.sessionid,
					contentType: "application/x-www-form-urlencoded",
					data: {
						caoyaoids: medArray.join(","),
						caoyaocount: numArr.join(","),
						keliids: med1Array.join(","),
						kelicount: numArr1.join(","),
						patientid: patientid,
						doctorid: doctorid
					},
					dataType: "json",
					async: false,
					beforeSend: function (request) {
						request.setRequestHeader("Token", localStorage.getItem("Authorization"));
					},
					success: function (data) {

					},
					error: function (data) {
						window.location.href = "../index.html";
					}
				});

				alert("保存成功");
			});
			$("#cz-bc-reset").click(function () {
				$("#main-zs").val("");
				$("#main-zd").val("");
				$("#main-yj").val("");
			});
			$("#cz-bc-save").click(function () {
				var zhusu = $("#main-zs").val();
				var zhenduan = $("#main-zd").val();
				var yijian = $("#main-yj").val();
				if (zhusu == "") {
					alert("请输入主诉");
					return;
				}
				if (zhenduan == "") {
					alert("请输入诊断");
					return;
				}
				if (yijian == "") {
					alert("请输入处理意见");
					return;
				}
				alert("保存成功");
			});

			/*药方弹出框-点击弹出按钮*/
			$("#xyt_kf_yfmb_popBox_btn").click(function () {
				$("#xyt_kf_yfmb_popBox").show();
				$("#xyt_kf_yfmb_popLayer").show();

				var doctorid = localStorage.getItem("doctorId");
				$.ajax({
					type: "POST",
					url: window.baseUrl +
						"/xunyitang/westPrescript/prescriptlist?jsessionid=" + window
						.sessionid,
					contentType: "application/x-www-form-urlencoded",
					data: {
						doctorId: doctorid
					},
					dataType: "json",
					async: false,
					beforeSend: function (request) {
						request.setRequestHeader("Token", localStorage.getItem("Authorization"));
					},
					success: function (data) {
						if(null!=data && null!=data.rows && data.rows.length>0){
							$("#xyt_kf_yfmb_content_left_ul1_list").empty();
							for(var i=0;i<data.rows.length;i++){
								var prescript = data.rows[i];
								$("#xyt_kf_yfmb_content_left_ul1_list").append('<li><a class="show-prescript-a" data-id="'+prescript.id+'">'+prescript.name+'</a></li>');
							}
							window.selectpescriptid=data.rows[0].id;
							refresh();
							$(".show-prescript-a").click(function(){
								window.selectpescriptid=$(this).data().id;
								refresh();
							});
						}
					},
					error: function (data) {
						window.location.href = "../index.html";
					}
				});

			});
			/*药方弹出框-点击关闭按钮*/
			$("#xyt_kf_yfmb_closeBox_btn").click(function () {
				$("#xyt_kf_yfmb_popBox").hide();
				$("#xyt_kf_yfmb_popLayer").hide();
			});

		})
	</script>
</body>

</html>